define(function () {
    return function (pane, store_id) {
        /**
         * 导航
         */
        {
            pane.html(utils.getHtml('split_table'));

            utils.addFilterGroupbtn(pane, {
                name: 'permissions',
                filters: [{value: "all", text: "全部"}, {value: "checked", text: "已分配"}]
            });
        }

        $('.left-menu', pane).html(utils.getPills({
            text: '角色列表',
            pills: dicts.role
        })).addClass('filter-list').addClass('filter-role').attr('data-name', 'role');


        //初始化工具
        utils.addTools(pane, [{className: 'save-permissions-btn', icon: 'fa-save', text: '保存权限'}]);
        $(pane).on('click', '.save-permissions-btn', function () {
            //保存权限
            utils.confirmation(this, {
                placement: 'left',
                optName: '保存权限',
                title: '你确定保存权限?',
                fnConfirm: function () {
                    var ids = [], role = utils.filterValue(pane, 'role');
                    table.find('.checkbox').each(function () {
                        if ($(this).prop("checked")) {
                            ids.push(this.value);
                        }
                    });
                    return adminApi('permissions_save', JSON.stringify({role: role, ids: ids}));
                }
            });
        });

        //初始化表格
        var table = utils.dataTable(pane, {
            paginate: false,
            info: false,
            filter: false,
            columns_arrays: [
                ["id", "#"],
                ["id", '选择', false, function (id, t, row) {
                    return '<input type="checkbox" class="checkbox" ' + (row.checked ? 'checked="checked"' : '') + ' value="' + id + '"> ';
                }],
                ["name", "权限名", false],
                ["object_type", "对象", false],
                ["action_type", "操作", false]
            ],
            sorting: [[0, 'desc']],
            fnServerData: function (paramData) {
                return adminApi('permissions_find', paramData);
            }
        });

        //初始化分屏
        var splitLeft = $('.split-left', pane);
        utils.initSplit(pane.attr('id'), {
            sizes: ['calc(0% + 187px)', 'calc(100% - 193px)'],
            minSize: 6,
            gutterSize: 6
        });
    }
});